package com.caogl.zxing_gen_qrcode_barcode_demo;

import com.google.zxing.WriterException;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class GUI extends JPanel {

    private BufferedImage image;
    public GUI() throws WriterException {
        image = new GenBufferedImageWithBarCodeQRcodeDemo().gen_image();
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(image.getWidth(), image.getHeight());
    }


    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, null);
    }

    private static void create() throws WriterException, IOException {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new GUI());
        f.pack();
        f.setVisible(true);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    create();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}